<?php defined("MAIN_DIR") or die("No direct access");

if (isset($_GET['act']) && $_GET['act'] != "")
{
	if ($_GET['act'] == "delete") {
		
		if (isset($_GET['id']) && $_GET['id'] != "") {
			mysql_query("delete from `vote` where `vote_id` = '$_GET[id]' limit 1");
			to("/admin/mentions/");
		}
	} elseif ($_GET['act'] == "delete_all") {
		
		if (isset($_GET['id']) && $_GET['id'] != "") {
			mysql_query("delete from `vote` where `bank_id` = '$_GET[id]'");
			to("/admin/mentions/");
		}
	}
}

require_once ADMIN.HEADFILE;
?>
<div align="left">
	<h1>Выбор банка</h1><?php
	$banks_query = "select `bank`.`bank_id`,`bank`.`name`,SUM(`vote`.`mark`) as `rating`,COUNT(`vote`.`mark`) as `count` from `bank`,`vote` where `bank`.`bank_id` = `vote`.`bank_id` and `bank`.`city_id` = '$_SESSION[city_admin]' group by `bank_id` order by `name`";

	$limit = 10;
	$banks_result = mysql_query($banks_query);
	$count = mysql_num_rows($banks_result);
	$page = 1;
	if (isset($_GET['page']))
		$page = $_GET['page'];
	$max_page = ceil($count/$limit);
	if ($max_page == 0)
		$max_page++;
	if ($page > $max_page)
		$page = $max_page;
	elseif ($page < 1)
		$page = 1;
	$start_list = (ceil($page)-1)*$limit;
	$banks_query .= " limit $start_list,$limit";
	$banks_result = mysql_query($banks_query);
	$banks_count = mysql_num_rows($banks_result);
	?>
	<table cellpadding="5" cellspacing="0" class='light'>
		<tr id='header'>
			<td width="30px" style="border-bottom:1px gray solid">ID</td>
			<td width="300px" style="border-bottom:1px gray solid">Название</td>
			<td width="50px" style="border-bottom:1px gray solid">Рейтинг</td>
			<td width="50px" style="border-bottom:1px gray solid">Отзывов</td>
			<td width="200px" style="border-bottom:1px gray solid">Действия</td>
		</tr><?php
		while ($bank_row = mysql_fetch_array($banks_result))
		{
			?><tr>
				<td><?php echo $bank_row['bank_id']?></td>
				<td><a href='/admin/mentions/?bank_id=<?php echo $bank_row['bank_id']?>'><?php echo $bank_row['name']?></td>
				<td><?php echo $bank_row['rating']?></td>
				<td><?php echo $bank_row['count']?></td>
				<td>
					<a onclick='return confirm_del()' href='/admin/mentions/delete_all/<?php echo $bank_row['bank_id']?>'>Удалить отзывы</a>
				</td>
			</tr><?php
		}
	?></table>
	<div id="pages"><?php require_once APP."pageskin.php"; ?></div>
</div>

<?php require_once ADMIN.FOOTERFILE; ?>